/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table.editor;

import com.rw.table.TableInfo;
import com.rw.table.formatter.ICellFormatter;
import com.toedter.calendar.JDateChooser;
import java.awt.Component;
import java.util.Date;

/**
 *
 * @author Rene Tapia
 */
public class DateCellEditor extends ACellEditor {

    private JDateChooser dateChooser;

    public DateCellEditor(String pattern) {
        this.dateChooser = new JDateChooser();
        this.dateChooser.setDateFormatString(pattern);
    }

    @Override
    public Component getComponent(TableInfo info) {
        Object value = info.getValue();
        if (value != null) {
            Date date = (Date) value;
            this.dateChooser.setDate(date);
        }
        return dateChooser;
    }

    @Override
    public Object getCellEditorValue(ICellFormatter formatter) {
        return this.dateChooser.getDate();
    }
}
